package com.wjh.garbagetype.result;

import java.io.Serializable;

/**
 * @Description 返回结果封装类
 * @Date 2020/4/18 11:16
 * @Created by jiahui.wu
 */
public class Result<T> implements Serializable {

    private static final long serialVersionUID = 4273778950483672657L;

    /**
     *  请求成功响应code
     */
    private static final Integer SUCCESS_CODE = 0;

    private static final String SUCCESS_MESSAGE = "成功";

    /**
     *  响应结果码
     */
    private Integer code = SUCCESS_CODE;

    /**
     *  响应结果描述
     */
    private String message = SUCCESS_MESSAGE;

    private T result;

    /**
     *  操作成功返回结果
     * @param t
     * @param <T>
     * @return
     */
    public static <T> Result success(T t) {
        Result result = new Result();
        result.setT(t);
        return result;
    }


    /**
     *  操作失败返回结果
     * @param code
     * @param message
     * @param <T>
     * @return
     */
    public static <T> Result error(Integer code, String message) {
        Result result = new Result();
        result.setCode(code);
        result.setMessage(message);
        return result;
    }


    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getT() {
        return result;
    }

    public void setT(T result) {
        this.result = result;
    }
}
